package be.bonamis.umpire.domain.quiz;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;

import org.apache.openjpa.persistence.Externalizer;
import org.apache.openjpa.persistence.Factory;
import org.apache.openjpa.persistence.Persistent;
import org.joda.time.DateTime;

@Entity
public class Quiz implements Serializable{

	private static final long serialVersionUID = 6497553680839666146L;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private long id;

	@Persistent
	@Externalizer("toDate")
	@Factory("Quiz.dateTimeToJoda")
	private DateTime creationDay;

	@OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.EAGER)
	private List<Question> questions;

	public Quiz() {
		questions = new ArrayList<Question>();
	}

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public DateTime getCreationDay() {
		return creationDay;
	}

	public void setCreationDay(DateTime creationDay) {
		this.creationDay = creationDay;
	}

	public List<Question> getQuestions() {
		return questions;
	}

	public void setQuestions(List<Question> questions) {
		this.questions = questions;
	}
	
	public static DateTime dateTimeToJoda(Date dateTime) {
		return new DateTime(dateTime) ;       
    }
}
